package com.zink.ezequiel.codes.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.zink.ezequiel.codes.R;
import com.zink.ezequiel.codes.data.model.Entry;
 
 
public class CodesAdapter extends ArrayAdapter<Entry> {
 
    private int resource;
    private String response;
    private Context context;
    //Initialize adapter
    public CodesAdapter(Context context, int resource) {
        super(context, resource);
        this.resource=resource;
 
    }
     
     
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        LinearLayout entryView;
        //Get the current alert object
        Entry entry = getItem(position);
         
        //Inflate the view
        if(convertView==null)
        {
        	entryView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi;
            vi = (LayoutInflater)getContext().getSystemService(inflater);
            vi.inflate(resource, entryView, true);
        }
        else
        {
        	entryView = (LinearLayout) convertView;
        }
        //Get the text boxes from the listitem.xml file
        TextView entryName =(TextView)entryView.findViewById(R.id.entryName);
        TextView userName =(TextView)entryView.findViewById(R.id.entryUserName);
         
        //Assign the appropriate data from our entry object above
        entryName.setText(entry.getEntryName());
        userName.setText(entry.getUserName());
         
        return entryView;
    }
 
}

